package com.mia.props.client.renderers;

import com.mia.craftstudio.libgdx.Vector3;
import com.mia.craftstudio.minecraft.client.CSClientModelWrapperVBO;
import com.mia.craftstudio.minecraft.forge.CSLibMod;
import com.mia.props.DecoModelMetadata;
import com.mia.props.Props;
import com.mia.props.common.TileProps;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.MovingObjectPosition.MovingObjectType;
import net.minecraftforge.client.MinecraftForgeClient;
import org.lwjgl.opengl.GL11;

import java.util.HashMap;
import java.util.Map;

public class RendererProp extends TileEntitySpecialRenderer {
   private final Vector3 halfBlock = new Vector3(0.5F, 0.0F, 0.5F);
   private final Vector3 neghalfBlock = new Vector3(-0.5F, 0.0F, -0.5F);

   public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
      int renderPass = MinecraftForgeClient.getRenderPass();
      TileProps tile = (TileProps)tileentity;
      GL11.glPushMatrix();
      GL11.glTranslated(x, y, z);
      boolean showOutline = false;
      MovingObjectPosition target = Minecraft.getMinecraft().objectMouseOver;
      if (CSLibMod.displayOutline && tileentity != null && target != null && target.typeOfHit == MovingObjectType.BLOCK && target.blockX == tileentity.xCoord && target.blockY == tileentity.yCoord && target.blockZ == tileentity.zCoord) {
         showOutline = true;
      }

      if (tile != null) {
         ((CSClientModelWrapperVBO) ((DecoModelMetadata) Props.modelData.get(tile.getRenderingType())).wrapper).render(tileentity, f, renderPass, showOutline, (float) tile.rotation * 22.5F, Vector3.invY, this.halfBlock, this.neghalfBlock);
      }
      GL11.glPopMatrix();
   }

   public static Map getModelData() {
      return Props.modelData;
   }
}
